package controleur;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import javax.swing.JFileChooser;

import model.Environnement;

public class SauveGrille implements ActionListener {
	private Environnement env = null;

	public SauveGrille(Environnement env) {
		this.env = env;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		JFileChooser defautChooser = new JFileChooser();
		defautChooser.showOpenDialog(null);

		File f = defautChooser.getSelectedFile();
		if(f == null)
			return;
		ObjectOutputStream obj = null;
		try {
			obj = new ObjectOutputStream(new FileOutputStream(f));
			obj.writeObject(env.getMapCellule());
			obj.writeInt(env.getHauteur());
			obj.writeInt(env.getLargeur());
			obj.flush();
			obj.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
